<template>
  <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page="pageData.currentPage"
    :page-sizes="[4, 10, 20, 40]"
    :page-size="pageData.pageSize"
    layout="total, sizes, prev, pager, next, jumper"
    :total="pageData.total"
  >
  </el-pagination>
</template>

<script>
export default {
  props: {
    pageData: { type: Object, default: () => {} }
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 4,
      total: 0
    }
  },
  watch: {
    pageData: {
      handler(n, o) {
        const num = Math.ceil(this.pageData.total / this.pageData.pageSize)
        if (num < this.pageData.currentPage) {
          this.handleCurrentChange(num)
        }
      },
      deep: true
    }
  },
  methods: {
    /* 分页器 */
    handleSizeChange(val) {
      this.pageData.pageSize = val
      this.$emit('pagingIncident')
    },
    handleCurrentChange(val) {
      this.pageData.currentPage = val || 1
      this.$emit('pagingIncident')
    }
  }
}
</script>

<style lang="less" scoped>
.el-pagination {
  margin-top: 20px;
}
</style>
